package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.item.entity.MedicinalInf;
import cn.zysuyuan.item.service.MedicinalInfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2019/10/28 15:54
 */

@Api(tags = "中药材资源浏览")
@Controller
@RequestMapping("medicinalInf")
public class MedicinalInfController {

    @Autowired
    private MedicinalInfService medicinalInfService;

    @ApiOperation(value = "中药材资源列表", notes = "用于中药资源浏览")
    @GetMapping("medicinalinflist")
    public ResponseEntity<PageResult<MedicinalInf>> selectMedicinalInf(@RequestParam Map<String,Object> map){
        PageResult<MedicinalInf> result = this.medicinalInfService.selectList(map);
//        if (CollectionUtils.isEmpty(result.getRows())){
//            return ResponseEntity.notFound().build();
//        }
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "单个药材信息", notes = "单个药材信息")
    @GetMapping("medicinalinfdetails")
    public ResponseEntity<PageResult<MedicinalInf>> medicinalinfDetails(@RequestParam Map<String,Object> map){
        PageResult<MedicinalInf> result = this.medicinalInfService.medicinalDetails(map);
        if (CollectionUtils.isEmpty(result.getRows())){
            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(result);
    }

}
